package com.yn.xr.front.user.service.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yn.xr.common.exception.base.BaseException;
import com.yn.xr.common.util.EncryptUtil;
import com.yn.xr.front.user.service.UserRegisterService;
import com.yn.xr.middleware.user.rmi.UserRegisterRmiService;
import com.yn.xr.user.mode.UserRegister;

/**
 * @description:用户业务接口实现类
 * @fileName:UserRegisterServiceImpl.java
 * @createTime:2015年1月20日 下午7:33:24
 * @author:陈权福
 * @version 1.0.0
 * 
 */
@Service("userRegisterService")
public class UserRegisterServiceImpl implements UserRegisterService {

	@Resource
	private UserRegisterRmiService userRegisterRmiService;

	private static final Logger log = LoggerFactory
			.getLogger(UserRegisterServiceImpl.class);

	@Override
	public UserRegister login(String accName, String pwd) throws BaseException {
		log.info("will enter rmi login function......");
		UserRegister user = null;
		try {
			// 将密码设置为md5加密
			String md5Pwd = EncryptUtil.md5(pwd).toUpperCase();// 统一为MD5大写
			log.info("进入登录方法");
			user = userRegisterRmiService.findUserRegisterByAccAndPwd(accName, md5Pwd );
		} catch (BaseException e) {
			log.error(e.getErrorMsg());
			throw e;
		}
		return user;
	}

	@Override
	public UserRegister getNewUsBySessionOb(Long userId) throws BaseException {

		return null;
	}
	
	/**
	 * @Description: 根据userid获取用户对象
	 * @author wangpinwen
	 * @date 2015年8月25日 上午11:39:13 
	 * @version V1.0.0
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	@Override
	public UserRegister getUserRegisterByUserId(Long userId) throws Exception {
		return userRegisterRmiService.getUserRegisterByUserId( userId );
	}

}
